package com.sugar.psych.assessment.module.business.controller.app.userleavemessage;

import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import com.sugar.psych.assessment.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.psych.assessment.module.business.controller.admin.userleavemessage.vo.UserLeaveMessagePageReqVO;
import com.sugar.psych.assessment.module.business.controller.admin.userleavemessage.vo.UserLeaveMessageRespVO;
import com.sugar.psych.assessment.module.business.controller.admin.userleavemessage.vo.UserLeaveMessageSaveReqVO;
import com.sugar.psych.assessment.module.business.controller.app.userleavemessage.vo.AppUserLeaveMessagePageReqVO;
import com.sugar.psych.assessment.module.business.controller.app.userleavemessage.vo.AppUserLeaveMessageRespVO;
import com.sugar.psych.assessment.module.business.controller.app.userleavemessage.vo.CreateLeaveMsgReqVO;
import com.sugar.psych.assessment.module.business.controller.app.userleavemessage.vo.LikedLeaveMsgReqVO;
import com.sugar.psych.assessment.module.business.dal.dataobject.userleavemessage.UserLeaveMessageDO;
import com.sugar.psych.assessment.module.business.service.userleavemessage.UserLeaveMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.successApp;

@Tag(name = "APP - 用户留言")
@RestController
@RequestMapping("/psych/user-leave-message")
@Validated
public class AppUserLeaveMessageController {

    @Resource
    private UserLeaveMessageService userLeaveMessageService;

    @PostMapping("/create")
    @Operation(summary = "创建用户留言")
    public CommonResult<Long> createUserLeaveMessage(@Valid @RequestBody CreateLeaveMsgReqVO createReqVO) {
        return successApp(userLeaveMessageService.appCreateUserLeaveMessage(createReqVO, SecurityFrameworkUtils.getLoginUserId()));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户留言")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteUserLeaveMessage(@RequestParam("id") Long id) {
        userLeaveMessageService.appDeleteUserLeaveMessage(id, SecurityFrameworkUtils.getLoginUserId());
        return successApp(true);
    }

    @GetMapping("/self-page")
    @Operation(summary = "获得用户自己的留言分页")
    public CommonResult<PageResult<AppUserLeaveMessageRespVO>> getUserLeaveMessagePage(@Valid PageParam pageParam) {
        return successApp(userLeaveMessageService.appGetUserLeaveMessagePage(pageParam, SecurityFrameworkUtils.getLoginUserId()));
    }

    @PostMapping("/liked")
    @Operation(summary = "点赞/取消点赞")
    public CommonResult<Boolean> userLeaveMessageLiked(@Valid @RequestBody LikedLeaveMsgReqVO reqVO) {
        userLeaveMessageService.userLeaveMessageLiked(reqVO.getId(), SecurityFrameworkUtils.getLoginUserId());
        return successApp(true);
    }

    @PostMapping("/page")
    @Operation(summary = "获取所有留言墙分页")
    public CommonResult<PageResult<AppUserLeaveMessageRespVO>> selectUserLeaveMessagePage(AppUserLeaveMessagePageReqVO reqVO) {
        return successApp(userLeaveMessageService.selectUserLeaveMessagePage(reqVO, SecurityFrameworkUtils.getLoginUserId()));
    }
}